package com.tegistuff.webos.run.debugger.commands;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * WebOSLookUpCommand.java
 *
 * Copyright (C) 2012 Timo Tegtmeier.
 * All rights reserved.
 */
public class WebOSLookUpCommand extends WebOSDebuggerCommand {
    
    private JSONArray myRefs;
    private JSONObject myObjects;
    
    public WebOSLookUpCommand() {
    }
    
    public WebOSLookUpCommand(List<Integer> refs) {
        setRefs(refs);
    }

    public void setRefs(List<Integer> refs) {
        myRefs = new JSONArray(refs);
    }
   
    @Override
    public void execute() throws Exception {
        JSONObject args = new JSONObject();
        args.put("includeSource", false);
        args.put("handles", myRefs);
        JSONObject request = new JSONObject();
        request.put("command", "lookup");
        request.put("arguments", args);
        runRequest(request);
    }

    @Override
    protected void onSuccess() throws JSONException {
        myObjects = ourResponse.getJSONObject("body");
    }

    public JSONObject getVariables() {
        return myObjects;
    }
}
